package com.example.testapp;

import java.util.HashMap;
import java.util.Map;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;

import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;

public class MainActivity extends Activity {

	OnClickListener b1Listener = new OnClickListener() {
		public void onClick(final View view){
			
			Map<String,String> valueMap = new HashMap<String, String>();
			valueMap.put("fadeTime","0");
			new SendMessageToProxy().execute(
					JSONHelper.createMessage("LP.LIGHTCONTROL", "kitchen_cooking_light_on" , valueMap));
		}
	};
	
	OnCheckedChangeListener s1Listener = new OnCheckedChangeListener(){
		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
			if(isChecked == true){
				Map<String,String> valueMap = new HashMap<String, String>();
				valueMap.put("fadeTime","0");
				new SendMessageToProxy().execute(
						JSONHelper.createMessage("LP.LIGHTCONTROL", "kitchen_cooking_light_on" , valueMap));
			}else{
				Map<String,String> valueMap = new HashMap<String, String>();
				valueMap.put("fadeTime","0");
				new SendMessageToProxy().execute(
						JSONHelper.createMessage("LP.LIGHTCONTROL", "kitchen_cooking_light_off" , valueMap));
			}
		}
	};
	Button b1;
	Switch s1;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		this.b1 = (Button) this.findViewById(R.id.button1);
		b1.setOnClickListener(b1Listener);
		
		this.s1 = (Switch) this.findViewById(R.id.switch1);
		s1.setOnCheckedChangeListener(s1Listener);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
	
}
